//
//  SRSettingVc.m
//  sr01sdkProject
//
//  Created by   on 2022/5/27.
//

#import "CASettingVc.h"
#import "LKTools.h"
#import "CARingSDK.h"
#import "ConfigModel.h"

@interface CASettingVc ()<UITableViewDelegate, UITableViewDataSource, CABleDataProtocal, CABleScanProtocal>

@property(strong, nonatomic)UITableView *tableView;
@property(strong, nonatomic)NSArray<NSNumber *> *dataArray;



@end

@implementation CASettingVc

- (void)viewDidLoad {
    [super viewDidLoad];
    WEAK_SELF
    [self customNavStyleNormal:@"Settings" BackBlk:^{
        STRONG_SELF
        [strongSelf.navigationController popViewControllerAnimated:YES];
    }];
    
    self.dataArray = @[
      
                        @(TAG_GET_SR28_ALGO), // 获取算法
                        @(TAG_SET_SR28_ALGO), // 设置算法
    ];
    [self initUI];
}

-(void)initUI {
    [self.view addSubview:self.tableView];
    
    [self.tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.top.equalTo(self.view);
        make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
    }];
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [CARingSDK instance].bleDataDelegate = self;
    [CARingSDK instance].blescanDelegate = self;
    
}



-(void)changeAlgothem
{
    WEAK_SELF
    UIAlertController * alertVc = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    
    UIAlertAction *actionBind = [UIAlertAction actionWithTitle:_L2(L_third_alto) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        STRONG_SELF
        [[CARingSDK instance] functionNalgSetDeviceAlgorithm:1];

    }];

    [alertVc addAction:actionBind];
    
    UIAlertAction * actionUnbind = [UIAlertAction actionWithTitle:_L2(L_lt_algo) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        STRONG_SELF
        [[CARingSDK instance] functionNalgSetDeviceAlgorithm:0];

    }];;
   
    [alertVc addAction:actionUnbind];
  
        
    UIAlertAction * actionCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
    [alertVc addAction:actionCancel];

    [self presentViewController:alertVc animated:YES completion:nil];
    
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44.0f;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"settingVC" forIndexPath:indexPath];
    
    switch (self.dataArray[indexPath.row].unsignedIntValue) {
     
        case TAG_GET_SR28_ALGO:
        {
            cell.textLabel.text = _L2(L_qry_curr_algoth);
        }
            break;
        case TAG_SET_SR28_ALGO:
        {
            cell.textLabel.text = _L2(L_set_curr_algoth);

        }
            break;
        default:
            break;
    }
    
    return cell;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    // TAG_GET_SR28_ALGO
    if (self.dataArray[indexPath.row].unsignedIntValue == TAG_GET_SR28_ALGO) {
        // 查询算法
        [[CARingSDK instance] functionNalgGetDeviceAlgorithm];
    }
    
    if (self.dataArray[indexPath.row].unsignedIntValue == TAG_SET_SR28_ALGO) {
        // 设置算法
        [self changeAlgothem];
    }
    
}




-(UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"settingVC"];
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}


- (void)caBleCmdExcute:(EXCUTED_CMD)cmd Succ:(BOOL)isSucc Reason:(CA_CMD_EXECTE_ERROR_REASON)reason Data:(nonnull NSData *)originData {
    
}

- (void)caBleDeviceBatteryLevel:(NSInteger)batteryLevel IsCharging:(BOOL)isCharging{
    
}



- (void)caBleDeviceDidReadyForReadAndWrite:(nonnull CABLeService *)service {
    
}

- (void)caBleDeviceInfo:(nonnull CADeviceInfo *)devInfo {
    
}


- (void)caBleDeviceRealtimeTemperature:(nonnull NSNumber *)temperature {
    
}

- (void)caBleDidConnectPeripheral:(nonnull CABLeService *)service {
    
}

- (void)caBleDidDisconnectPeripheral:(nonnull CABLeService *)service {
    
}

- (void)caBleFailConnectPeripheral:(nonnull CBPeripheral *)peripheral Error:(nonnull NSError *)error {
    
}

- (void)srBleHistoryData:(nonnull CAHistoryData *)hisData IsComplete:(BOOL)isComplete {
    
}

- (void)caBleHistoryDataCount:(NSInteger)count {
    
}

- (void)srBleHistoryDataTimeout {
    
}

- (void)caBleHistorySr03Data:(nonnull CAHistoryDataSR03 *)hisData IsComplete:(BOOL)isComplete {
    
}

- (void)caBleMeasureDuration:(NSInteger)seconds {
    
}

- (void)caBleOEMAuthResult:(BOOL)authSucceddful {
    
}



- (void)caBleIsBinded:(BOOL)isBinded
{
    
}


- (void)caBleRealtimeHRV:(nonnull NSNumber *)hrv BloodOxygen:(nonnull NSNumber *)bloodOxygen HeartRate:(nonnull NSNumber *)hr Status:(REALTIME_STATUS)status {
    
}

- (void)caBleSN:(nonnull NSString *)sn SnData:(nonnull NSData *)snData {
    
}


/// User information reporting
/// - Parameters:
///   - gender:  0 male, 1 female
///   - ageYear: range 1-115
///   - height:  in mm, range 1200-3000
///   - weight:  in kg, range 30-200
-(void)caBleUsrInfoFromoDev:(NSUInteger)gender
                Age:(NSUInteger)ageYear
              Height:(NSUInteger)height
                     Weight:(NSUInteger)weight
{
    
}

-(void)caBleNALGDevMeaDuration:(CACS_DEV_MEA_DURA_AND_TM_TYPE)meaType MeaDuraofNoSlepPerd:(uint32_t)meaduraNoSleep MeaIntervOfNoSlepPerd:(uint32_t)meaIntervNoSleep
      MeaDuraofInSlepPerd:(uint32_t)meaduraInSleep MeaIntervInNoSlepPerd:(uint32_t)meaIntervInSleep
{
    
}


/// 上报算法类型 0-linkgtop算法 1-new算法
-(void)caBleNALGalgorithmType:(uint8_t)algorithmType;
{
    [self showAlertWarningWithTitle:_L2(L_curr_algo) Msg:[NSString stringWithFormat:@"%@:%@", _L2(L_curr_algo), !algorithmType ? _L2(L_lt_algo) : _L2(L_third_alto) ] btnCancel:@"Ok" Compelete:nil];
}


/// Report the last activity (上报最后一条活动)
/// - Parameter activity: Activity data
-(void)caBleLastActivity:(CAnAlgGrandActivity *)activity
{
    
}


/// sr28实时测量数据
/// - Parameter realMeasurData: 实时测量数据
-(void)caBleNALGRealMeasu:(CAnAlgRealMeasure *)realMeasurData;
{
    
}

/// Report the number of activity detection/swimming/sleep history data
/// - Parameters:
///   - count: The amount of data
///   - minUUid: The minimum uuid of the data reported this time
///   - maxUUid: The maximum uuid of the data reported this time
-(void)caBleHisCntOfActivityAndSwimAndSleep:(NSUInteger)count MinUUid:(uint32_t)minUUid MaxUUid:(uint32_t)maxUUid
{
    
}


@end

